var app = getApp();
Page({
  data: {
    tel: ''
  },

  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    //ajax请求数据
    wx.request({
      url: app.api.hostUrl + '/Api/Web/getconfig',
      method: 'post',
      data: {},
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var config = res.data.config;
        that.setData({
          tel: config.tel
        })
      },
      error: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      }
    })
  },

  //提交反馈
  bindFormSubmit: function (e) {
    var that = this;
    var content = e.detail.value.textarea;
    if (!content) {
      wx.showToast({
        title: '请输入反馈内容再提交！',
        duration: 2000
      });
      return false;
    }
    wx.request({
      url: app.api.hostUrl + '/Api/Web/feedback',
      method: 'post',
      data: {
        uid: app.api.userId,
        content: content,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var status = res.data.status;
        if (status==1) {
          wx.showToast({
            title: '保存成功！',
            duration: 2000
          });
          that.setData(
            {
              showModalStatus: false,
            }
          );
        } else {
          wx.showToast({
            title: res.data.err,
            duration: 2000
          });
        }
      },
      error: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      }
    })
  },

  calling: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.tel,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },

    // 弹窗
   setModalStatus: function (e) {
    console.log("设置显示状态，1显示0不显示", e.currentTarget.dataset.status);
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export()
    })
    if (e.currentTarget.dataset.status == 1) {
      this.setData(
        {
          showModalStatus: true
        }
      );
    }
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation
      })
      if (e.currentTarget.dataset.status == 0) {
        this.setData(
          {
            showModalStatus: false
          }
        );
      }
    }.bind(this), 200)
  },
})